using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Perks{
#region RequirementPairDefinition
	public struct RequirementPair{
		public RequirementPair(ATTRIBUTES attrib, float valueRequired){
			baseAttribute = attrib;
			requiredValue = valueRequired;
		}
		public ATTRIBUTES baseAttribute;
		public float requiredValue;
		public override string ToString ()
		{
			return "" + baseAttribute + ": " + requiredValue;
		}
	}
#endregion
	public abstract class Perk{
	#region Singleton List of Perks		
		private static Dictionary<string, Perk> existingPerks;
		private static void CreateAllPerks(){
			existingPerks = new Dictionary<string, Perk>();


            //Implemented
            existingPerks.Add(SilentAssassin.Name, new SilentAssassin());
            existingPerks.Add(RifleProficiency.Name, new RifleProficiency());
            existingPerks.Add(DoubleStamina.Name, new DoubleStamina());
            existingPerks.Add(FastManeuvers.Name, new FastManeuvers());
            existingPerks.Add(SniperProficiency.Name, new SniperProficiency());
            existingPerks.Add(TransportBodies.Name, new TransportBodies());
            existingPerks.Add(BackpackIncrease.Name, new BackpackIncrease());
            existingPerks.Add(BackpackIncreasePlus.Name, new BackpackIncreasePlus());

            //Not implemented
			/*existingPerks.Add(AllTerrain.Name, new AllTerrain() );
			existingPerks.Add(Disguise.Name, new Disguise() );
			existingPerks.Add(Driver.Name, new Driver() );
			existingPerks.Add(HandgunSilencer.Name, new HandgunSilencer() );
			existingPerks.Add(LockPicking.Name, new LockPicking() );
			existingPerks.Add(ShotgunProficiency.Name, new ShotgunProficiency() );
			existingPerks.Add(TrapFinding.Name, new TrapFinding() );*/
		}
		public static Perk GetPerk(string perkName){
			if (existingPerks == null)
				CreateAllPerks();
			
			if (existingPerks.ContainsKey(perkName) )
				return existingPerks[perkName];
			else
				return null;
		}
		public static Dictionary<string, Perk> GetPerksDictionary(){
			if (existingPerks == null)
				CreateAllPerks();
			return existingPerks;	
		}
	#endregion
		protected string description;
		protected int equipCost;
		/// <summary>
		/// Este valor es el que se aplica al bonus del atributo.
		/// </summary>
		protected float bonusValue;
		/// <summary>
		/// Este valor es el que se aplica al porcetange de bonus del atributo.
		/// </summary>
		protected float bonusPercentage;
		protected RequirementPair[] requirements;
		
		public int GetCost(){return equipCost;}
		public RequirementPair[] GetRequirements(){ return requirements;}
		public string GetRequirementsDescription(){
			string rec = "\nREQUIREMENTS:\n";
			if (requirements == null){
				rec += "NONE";
			}else{
				foreach(RequirementPair pair in requirements){
					rec += pair.ToString();
					rec += "\n";
				}
			}
			return rec;
		}
		public string GetDescription(){return this.description;}
		protected abstract void SetRequirements();
		public abstract void OnEquip(AttributeSet aSet);
		public abstract void OnUnEquip(AttributeSet aSet);
		public abstract string GetName();
	}
}